#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution{
    public:
    //my ans
    int ans1(vector<int>& height){
        int length = height.size();
        int p_l = 0, p_r = length - 1;
        int max_water = 0;
        int min_heigh;
        while(p_l < p_r){
            min_heigh = min(height[p_l], height[p_r]);
            max_water = max(max_water, min_heigh * (p_r - p_l));
            if(min_heigh == height[p_l]){
                p_l++;
            }else{
                p_r--;
            }
        }
        return max_water;
    }
};

void test(){
    Solution s;
    vector<int> height = {1,8,6,2,5,4,8,3,7};
    int ret = s.ans1(height);
    cout << ret << endl;
}

int main(void){
    test();

    return 0;
}